//
//  BelowView.m
//  我的音频播放器
//
//  Created by dllo on 16/7/28.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "WJAudioBelowView.h"

#define AudioW WIDTH - 70
#define AudioH 50

@implementation WJAudioBelowView

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self resetAllSubviews];
    }
    return self;
}


- (void)resetAllSubviews {
    _playBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [_playBtn setImage:[UIImage imageNamed:@"icon_pause"] forState:UIControlStateNormal];
    [_playBtn setImage:[UIImage imageNamed:@"icon_play"] forState:UIControlStateSelected];
    [self addSubview:_playBtn];
    
    self.timeIntervalProgress = [[UIProgressView alloc]init];
    self.timeIntervalProgress.backgroundColor = [UIColor purpleColor];
    self.timeIntervalProgress.trackTintColor = BSLightGrayColor;
    self.timeIntervalProgress.progressTintColor = BSDarkGrayColor;
    [self addSubview:self.timeIntervalProgress];
    
    
    _progressSlider = [[UISlider alloc]init];
    _progressSlider.backgroundColor = BSClearColor;
    [_progressSlider setThumbImage:[UIImage imageNamed:@"icon_progress"] forState:UIControlStateNormal];
    [_progressSlider setThumbImage:[UIImage imageNamed:@"icon_progress"] forState:UIControlStateHighlighted];
    _progressSlider.maximumTrackTintColor = BSClearColor;
    _progressSlider.minimumTrackTintColor = BSRedColor;
    [self addSubview:_progressSlider];
    
    
    
    _currentTimeLabel = UILabel.new;
    _currentTimeLabel.backgroundColor = BSClearColor;
    _currentTimeLabel.font = [UIFont systemFontOfSize:13.0];
    _currentTimeLabel.textAlignment = NSTextAlignmentLeft;
    _currentTimeLabel.textColor = BSWhiteColor;
    [self addSubview:_currentTimeLabel];
    
    
    // 显示总时间
    _totalDurationLabel = UILabel.new;
    _totalDurationLabel.backgroundColor = BSClearColor;
    _totalDurationLabel.font = [UIFont systemFontOfSize:13.0];
    _totalDurationLabel.textAlignment = NSTextAlignmentRight;
    _totalDurationLabel.textColor = BSWhiteColor;
    [self addSubview:_totalDurationLabel];
    
    _playBtn.frame = CGRectMake(10, (AudioH - 50)/2.0, 0, 50);
    _currentTimeLabel.frame = CGRectMake(40, 0,0,AudioH);
    _totalDurationLabel.frame = CGRectMake(AudioW - 30,0,0,AudioH);
    _timeIntervalProgress.frame = CGRectMake(0,0,0,AudioH);
    _progressSlider.frame = CGRectMake(0,0,0,AudioH);
    _timeIntervalProgress.centerY = AudioH / 2.0;
}


// 高给40 宽 414 - 20
- (void)layoutSubviews {
    [super layoutSubviews];
}

- (void)resetViewWithEnabled:(BOOL)enabled {
    _timeIntervalProgress.centerY = AudioH / 2.0;
    if (enabled) {
        _playBtn.frame = CGRectMake(10, (AudioH - 50)/2.0, 50, 50);
        _currentTimeLabel.frame = CGRectMake(50, 0, 40, AudioH);
        _totalDurationLabel.frame = CGRectMake(AudioW - 50, 0, 40, AudioH);
        _timeIntervalProgress.frame = CGRectMake(90, 0, AudioW - 140, AudioH);
        _progressSlider.frame = CGRectMake(90, 0, AudioW - 140, AudioH);
    } else {
        _playBtn.frame = CGRectMake(10, (AudioH - 50)/2.0, 0, 50);
        _currentTimeLabel.frame = CGRectMake(40, 0,0,AudioH);
        _totalDurationLabel.frame = CGRectMake(AudioW - 30,0,0,AudioH);
        _timeIntervalProgress.frame = CGRectMake(0,0,0,AudioH);
        _progressSlider.frame = CGRectMake(0,0,0,AudioH);
    }
}
@end
